let BaseBean = require('./BaseControl');
let comDriver = require('@/common/driver');

class Bean extends BaseBean{
    constructor(param = {}) {
        super(param);
    }

    async build(form){
        await super.build(form);
        form.param.vMethod[this.vKey('buttonClick')] = () => { if (this.enabled && this.visible && this.param.onButtonClick) this.param.onButtonClick();};
        form.param.vMethod[this.vKey('labelClick')] = () => () => { if (this.param.onLabelClick) this.param.onLabelClick();};
        form.param.vMethod[this.vKey('blur')] = (event) => { if (this.param.onBlur) this.param.onBlur(event);};
        form.param.vMethod[this.vKey('focus')] = (event) => { if (this.param.onFocus) this.param.onFocus(event);};
        form.param.vMethod[this.vKey('change')] = (value) => { if (this.param.onChange) this.param.onChange(value);};
    }

    shortKeyClick(){
        if (this.dom) this.dom.focus();
    }

    showData(data) {
        if (!data) return;
        let field = this.param.showField || this.param.field;
        if (!field) return;
        this.text =data[field] || '';
    }

    packageData(data) {
        let field = this.param.packageField || this.param.field;
        if (!field) return;
        data[field] = this.text;
    }
}


module.exports = Bean;
